package com.tangmu.rabbits.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.tangmu.rabbits.R;
import com.tangmu.rabbits.adapter.optimization.ClassifyGoodsAdapter;
import com.tangmu.rabbits.widget.recycle.divider.GridDividerItemDecoration;
import com.tangmu.rabbits.widget.recycle.divider.GridDividerItemDecoration2;
import com.tangmu.rabbits.widget.recycle.divider.GridDividerItemDecoration4;
import com.tangmu.rabbits.widget.recycle.divider.GridDividerItemDecoration5;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 *
 */
public class BlankFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.goods_recyclerView)
    RecyclerView mRecyclerView;
    Unbinder unbinder;
    private ClassifyGoodsAdapter adapter;
    private List<Integer> datas = new ArrayList<>();
    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public BlankFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @return A new instance of fragment BlankFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static BlankFragment newInstance(String param1) {
        BlankFragment fragment = new BlankFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_blank, container, false);
        unbinder = ButterKnife.bind(this, view);

        initDatas();

        return view;
    }

    private void initDatas() {
        for (int i = 0; i < 10; i++) {
            datas.add(i);
        }

        mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        //mRecyclerView.addItemDecoration(new GridDividerItemDecoration5(getActivity()));
        //mRecyclerView.addItemDecoration(new com.tangmu.rabbits.widget.recycle.GridDividerItemDecoration(3, ContextCompat.getColor(getActivity(),R.color.line_e_color)));
        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.setFocusableInTouchMode(false);
        mRecyclerView.requestFocus();
        adapter = new ClassifyGoodsAdapter(getActivity(), datas);
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
